<?php

namespace app\common\model\printmanager;

use think\Model;


class Goods extends Model
{

    

    

    // 表名
    protected $name = 'self_goods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'category',
        'display_text',
    ];
    

    
    public function getDisplayList()
    {
        return ['0' => __('Display 0'), '1' => __('Display 1')];
    }


    public function getDisplayTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['display']) ? $data['display'] : '');
        $list = $this->getDisplayList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getCategoryAttr($value, $data){
        $value = isset($data['category_id']) ? $data['category_id'] : 0;
        return $value ? \app\common\model\printmanager\Category::find($value) : '';
    }

    public function getFileListAttr($value, $data) {
        $value = isset($data['images']) ? $data['images'] : '';

        $list = $value ? explode(",", $value) : [];
        $res = [];
        foreach ($list as $key => $v) {
            $res[] = [
            'file_url' => $v,
            'cdn_url' => cdnurl($v),
            ];
        }
        unset($key, $value, $list);
        return $res;
    }

}
